package com.geovis.emergency.spd.biz.command.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.geovis.common.auth.util.AuthUtil;
import com.geovis.common.mybatis.page.PageParam;
import com.geovis.common.mybatis.page.PageResult;
import com.geovis.emergency.spd.biz.command.mapper.TEpDisasterMapper;
import com.geovis.emergency.spd.biz.command.service.ITEpDisasterService;
import com.geovis.emergency.spd.biz.pc.service.IPcDrillDisasterEventService;
import com.geovis.emergency.spd.entity.command.entity.TEpDisaster;
import com.geovis.emergency.spd.entity.command.pojo.dto.TepDisasterReqDTO;
import com.geovis.emergency.spd.entity.command.pojo.vo.TepDisasterEventVO;
import com.geovis.emergency.spd.entity.pc.entity.PcDrillDisasterEvent;
import com.geovis.emergency.spd.entity.pc.entity.PcMessage;
import com.geovis.emergency.spd.entity.pc.pojo.vo.PcMessageVO;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Lonsho
 * @since 2022-10-25
*/

@Service
@RequiredArgsConstructor
@Slf4j
@DS("yjglyzt")
public class TEpDisasterServiceImpl extends ServiceImpl<TEpDisasterMapper, TEpDisaster> implements ITEpDisasterService {


    @Override
    public PageResult<TepDisasterEventVO> selectEventPage(PageParam<TepDisasterReqDTO> pageParam) {
        LambdaQueryWrapper<TepDisasterEventVO> wrapper = Wrappers.<TepDisasterEventVO>lambdaQuery();
        IPage<TepDisasterEventVO> page = baseMapper.selectEventPage(pageParam.buildPage(), wrapper);


        for (TepDisasterEventVO tepDisasterEventVO : page.getRecords()) {
            if (ObjectUtil.isAllNotEmpty(tepDisasterEventVO.getLongitude(),tepDisasterEventVO.getLatitude())){
                JSONObject geometry = new JSONObject();
                geometry.put("type","GroundPoint");
                JSONObject centerData = new JSONObject();
                centerData.put("lon",Double.valueOf(tepDisasterEventVO.getLongitude()));
                centerData.put("lat",Double.valueOf(tepDisasterEventVO.getLatitude()));
                centerData.put("hei",0);
                geometry.put("centerData",centerData);
                tepDisasterEventVO.setGeometry(geometry);

            }


        }

        return new PageResult<>(page);
    }

    @Override
    public List<TepDisasterEventVO> selectEventList(Wrapper<TepDisasterEventVO> wrapper) {
        return baseMapper.selectEventList(wrapper);
    }
}
